export const transferData = (dataObj) => {
  let list = []
  let analyseType = dataObj.analyse_type

  const dataPro = (arr) => {
    let list = []
    for (let i = 0; i < arr.length; i++) {
      arr.forEach(item => {
        for (let k in item) {
          if (k.indexOf(`__${i}`) !== -1) {
            list.push(item[k])
          }
        }
      })
    }
    return list.join(',')
  }

  if (analyseType === '01' || analyseType === '02') {
    let groupList = dataObj.group_list
    let dateList = dataObj.date_list
    let { data } = dataObj
    if (groupList === undefined) {
      return
    }
    groupList.forEach(item => {
      let listObj = {
        name: item,
        data: []
      }
      for (let i = 0; i < dateList.length; i++) {
        let n = null
        data.forEach((obj, index) => {
          if (dateList[i] === obj.MC000154__GSD) {
            let arr = []
            for (let key in obj) {
              if (key.indexOf('__GS__') !== -1) {
                arr.push({ [key]: obj[key] })
              }
            }
            if (dataPro(arr) === item) {
              n = index
            }
          }
        })
        if (n === null) {
          listObj.data.push(0)
        } else {
          listObj.name = item
          for (let key in data[n]) {
            if (key.indexOf('__GF__') !== -1 && key.indexOf('__PERCENT__') === -1) {
              listObj.data.push(data[n][key])
            }
          }
        }
      }
      list.push(listObj)
    })
  }
  return list
}
